package com.itboy.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.math.BigInteger;

/**
 * 全局配置序列化返回 JSON 处理
 */
@Slf4j
//@Configuration
public class JacksonConfigSerializer {

	@Primary
	@Bean
	public ObjectMapper objectMapper() {
		ObjectMapper objectMapper = new ObjectMapper();
		// 全局配置序列化返回 JSON 处理
		SimpleModule simpleModule = new SimpleModule();
		simpleModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE);
		simpleModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE);
		simpleModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE);
		objectMapper.registerModule(simpleModule);
		return objectMapper;
	}

}
